package com.hly.musicbackground.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hly.musicbackground.domain.Song;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface SongDao extends BaseMapper<Song> {

    @Update("update song set play_mp3_num = play_mp3_num + 1 where rid = #{rid}")
    int playMp3NumAutoincrement(int rid);


    @Update("update song set play_mp4_num = play_mp4_num + 1 where rid = #{rid}")
    int playMp4NumAutoincrement(int rid);

    @Insert("INSERT INTO song(rid, name, pic, pic120, song_time_minutes, hasmv, artist, release_date) \n" +
            "SELECT #{rid}, #{name}, #{pic}, #{pic120}, #{songTimeMinutes}, #{hasmv}, #{artist}, #{releaseDate}' \n" +
            "FROM song\n" +
            "WHERE NOT EXISTS(SELECT rid FROM song WHERE rid = #{rid})")
    void save(Song song);

    @Update("update song set status = #{status} where rid = #{rid}")
    int updateStatus(Song song);

    @Select("select pic from song where rid = (select rid from song_link where link = #{songSheetId} and type = 'song_sheet' order by song_link_id desc limit 0,1)")
    String getSongSheetPic(int songSheetId);
}
